package com.xydtech.system.service.impl;

import com.xydtech.common.core.domain.IndustryTree;
import com.xydtech.common.core.text.Convert;
import com.xydtech.system.domain.SysGbIndustry;
import com.xydtech.system.mapper.SysGbIndustryMapper;
import com.xydtech.system.service.ISysGbIndustryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 国标行业Service业务层处理
 *
 * @author JHON
 * @date 2021-09-17
 */
@Service
public class SysGbIndustryServiceImpl implements ISysGbIndustryService {
    @Autowired
    private SysGbIndustryMapper sysGbIndustryMapper;

    /**
     * 查询国标行业
     *
     * @param id 国标行业ID
     * @return 国标行业
     */
    @Override
    public SysGbIndustry selectSysGbIndustryById(Long id) {
        return sysGbIndustryMapper.selectSysGbIndustryById(id);
    }

    /**
     * 查询国标行业列表
     *
     * @param sysGbIndustry 国标行业
     * @return 国标行业
     */
    @Override
    public List<SysGbIndustry> selectSysGbIndustryList(SysGbIndustry sysGbIndustry) {
        return sysGbIndustryMapper.selectSysGbIndustryList(sysGbIndustry);
    }

    /**
     * 新增国标行业
     *
     * @param sysGbIndustry 国标行业
     * @return 结果
     */
    @Override
    public int insertSysGbIndustry(SysGbIndustry sysGbIndustry) {
        return sysGbIndustryMapper.insertSysGbIndustry(sysGbIndustry);
    }

    /**
     * 修改国标行业
     *
     * @param sysGbIndustry 国标行业
     * @return 结果
     */
    @Override
    public int updateSysGbIndustry(SysGbIndustry sysGbIndustry) {
        return sysGbIndustryMapper.updateSysGbIndustry(sysGbIndustry);
    }

    /**
     * 删除国标行业对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSysGbIndustryByIds(String ids) {
        return sysGbIndustryMapper.deleteSysGbIndustryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除国标行业信息
     *
     * @param id 国标行业ID
     * @return 结果
     */
    @Override
    public int deleteSysGbIndustryById(Long id) {
        return sysGbIndustryMapper.deleteSysGbIndustryById(id);
    }

    /**
     * 查询国标行业树列表
     *
     * @return 所有国标行业信息
     */
    @Override
    public List<IndustryTree> selectSysGbIndustryTree() {
        List<SysGbIndustry> sysGbIndustryList = sysGbIndustryMapper.selectSysGbIndustryList(new SysGbIndustry());
        List<IndustryTree> ztrees = new ArrayList<IndustryTree>();
        for (SysGbIndustry sysGbIndustry : sysGbIndustryList) {
            IndustryTree industryTree = new IndustryTree();
            industryTree.setId(sysGbIndustry.getIndustryCode());
            industryTree.setpId(sysGbIndustry.getUpIndustryCode());
            industryTree.setName(sysGbIndustry.getIndustryName());
            industryTree.setTitle(sysGbIndustry.getIndustryName());
            ztrees.add(industryTree);
        }
        return ztrees;
    }
}
